﻿<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
     version="1.0" xmlns:str="http://exslt.org/strings" xmlns:c="http://exslt.org/common"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    exclude-result-prefixes="str c x xsl">

	<xsl:output omit-xml-declaration="yes"   />

	<xsl:key name="availableTitles" match="//rows/row/AtoZTitle1[. != ''] | //rows/row/AtoZTitle2[. != '']" use="."/>

	<xsl:template match="/">

		<xsl:apply-templates select="rows/row/AtoZTitle1 | rows/row/AtoZTitle2">
			<xsl:sort select="." />
		</xsl:apply-templates>

	</xsl:template>

	<xsl:template match="AtoZTitle1 | AtoZTitle2">

		<xsl:if test="generate-id(..) = generate-id(key('availableTitles', .)[1]/..)">
			<div class="atoz">
				<span>
					<xsl:value-of select="."/>
				</span>
			</div>
		</xsl:if>

		<xsl:apply-templates select=".."/>

	</xsl:template>

	<xsl:template match="row">

		<a href="/{substring-after(FileRef, '#')}" class="atoz">
			<xsl:value-of select="Title"/>
		</a>
		<br/>

	</xsl:template>

</xsl:stylesheet>

